layui.use(['layer', 'form', 'table', 'ztree', 'laydate', 'admin', 'ax', 'func', 'tree', 'util'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ZTree = layui.ztree;
    var $ax = layui.ax;
    var laydate = layui.laydate;
    var admin = layui.admin;
    var func = layui.func;
    var tree = layui.tree;
    var util = layui.util;

    /**
     * 混音大师管理--参赛列表
     */
    var base = {
        tableId: "baseTable"    //表格id
    };
    
    var bases = {
            tableId: "baseTables"    //表格id
        };

    //渲染时间选择框
    laydate.render({
        elem: '#timeLimit',
        range: true,
        max: Feng.currentDate()
    });
    
    //渲染时间选择框
    laydate.render({
    	elem: '#timeLimits',
    	range: true,
    	max: Feng.currentDate()
    });

    /**
     * 初始化表格的列
     */
    base.initColumn = function () {
        return [[
            {type: 'checkbox'},
            {field: 'phone', align: "center", sort: true, title: '账号'},
            {field: 'mailbox', align: "center", sort: true, title: '邮箱'},
            {field: 'nickName', align: "center", sort: true, title: '艺名'},
            {field: 'userName', align: "center", sort: true, title: '姓名'},
            {field: 'sex', align: "center", sort: true, title: '性别' ,templet:function(d) {
            	if(d.sex == 1){
            		return "男";
            	}else if(d.sex == 2){
            		return "女";
            	}else{
            		return "未知";
            	}
            }},
            {field: 'user_type', align: "center", sort: true, title: '个人/组合',templet:function(d) {
            	if(d.user_type == 1){
            		return "个人";
            	}else if(d.user_type == 2){
            		return "组合";
            	}
            }
            },
            {field: 'division', align: "center", sort: true, title: '赛区'},
            {field: 'user_no', align: "center", sort: true, title: '参赛编号'},
            {field: 'address', align: "center", sort: true, title: '常住地'},
            {field: 'personal_work', align: "center", sort: true, title: '作品',
            	templet:'<div><img lay-filter="imgck" id="imgck" name="{{d.personal_work}}" style="height:30px;width:50px;" src="/assets/common/images/u3332.png"></div>'},
            	//templet:'<div style="line-height:0;font-size:0"><video width="100%" height="100%"  controls="controls"  loop="loop" src="{{d.personal_work}}" style="width:100%;height:100%;"></video></div>'},
            {field: 'create_time', align: "center", sort: true, title: '报名时间'},
            {field: 'totalCount', align: "center", sort: true, title: '总票数'},
            {field: 'dayCount', align: "center", sort: true, title: '今日新增票数'},
            {fixed: 'right', toolbar: '#toolBtn', title: '操作', align: 'center', width: 130}
        ]];
    };
    bases.initColumn = function () {
        return [[
        	  {type: 'checkbox'},
        	  {field: 'xuh', align: "center", sort: true, title: '排名'},
              {field: 'phone', align: "center", sort: true, title: '账号'},
              {field: 'mailbox', align: "center", sort: true, title: '邮箱'},
              {field: 'nickName', align: "center", sort: true, title: '艺名'},
              {field: 'userName', align: "center", sort: true, title: '姓名'},
              {field: 'sex', align: "center", sort: true, title: '性别' ,templet:function(d) {
              	if(d.sex == 1){
              		return "男";
              	}else if(d.sex == 2){
              		return "女";
              	}else{
              		return "未知";
              	}
              }},
              {field: 'user_type', align: "center", sort: true, title: '个人/组合',templet:function(d) {
              	if(d.user_type == 1){
              		return "个人";
              	}else if(d.user_type == 2){
              		return "组合";
              	}
              }
              },
              {field: 'division', align: "center", sort: true, title: '赛区'},
              {field: 'user_no', align: "center", sort: true, title: '参赛编号'},
              {field: 'address', align: "center", sort: true, title: '常住地'},
              {field: 'personal_work', align: "center", sort: true, title: '作品',
              	templet:'<div><img lay-filter="imgck" id="imgck" name="{{d.personal_work}}" style="height:30px;width:50px;" src="/assets/common/images/u3332.png"></div>'},
              	//templet:'<div style="line-height:0;font-size:0"><video width="100%" height="100%"  controls="controls"  loop="loop" src="{{d.personal_work}}" style="width:100%;height:100%;"></video></div>'},
              {field: 'create_time', align: "center", sort: true, title: '报名时间'},
              {field: 'totalCount', align: "center", sort: true, title: '总票数'},
              {field: 'dayCount', align: "center", sort: true, title: '今日新增票数'},
              {field: 'scoring', align: "center", sort: true, title: '评分'},
              {fixed: 'right', toolbar: '#toolBtns', title: '操作', align: 'center', width: 130}
        ]];
    };
    
    $(document).on('click', '#adopt', function(data) {
        var activityId = $(this).attr("data-id");
		 func.open({
	            type: 2,
	            shadeClose: true,
	            shade: 0.5,
	            area: '300px',
	            title: '查看',
	            maxmin: true, //开启最大化最小化按钮
	            content: Feng.ctxPath + "/modular/activity_apply/details/" + activityId,
	            tableId: base.tableId
	        });
    });
    
    $(document).on('click', '#addApp', function(data) {
    	var id = $(this).attr("data-id");
    	var scoring = $(this).attr("data-name");
    	layer.open({
    		type: 2,
    		shadeClose: true,
    		shade: 0.5,
    		area: [480+'px', 350+'px'],
    		title: '查看',
    		maxmin: true, //开启最大化最小化按钮
    		content: Feng.ctxPath + "/modular/activity_apply/refuse?id=" + id,
    		tableId: base.tableId
    	});
    });
    
    $(document).on('click', '#addApps', function(data) {
    	var id = $(this).attr("data-id");
    	var scoring = $(this).attr("data-name");
    	layer.open({
    		type: 2,
    		shadeClose: true,
    		shade: 0.5,
    		area: [480+'px', 350+'px'],
    		title: '查看',
    		maxmin: true, //开启最大化最小化按钮
    		content: Feng.ctxPath + "/modular/activity_apply/refuse?id=" + id+"&scoring="+scoring,
    		tableId: base.tableId
    	});
    });
    
    $(document).on('click', '#imgck', function(data) {
    	var videoHtml = '<div style="line-height:0;font-size:0"><video width="100%" height="100%"  controls="controls" autobuffer="autobuffer"  autoplay="autoplay"  loop="loop" src="'+$(this).attr("name")+'" style="width:100%;height:100%;"></video></div>';
    	layer.open({ 
    		type: 1, 
    		shade: false,
    		title: false,
    		area: [430+'px', 350+'px'],
    		content: videoHtml,
    		cancel: function () {
    			
    		}
	    });
    });
    
    //绑定事件
    $(document).on('click', '#btn', function(data) {
    	$(this).addClass("layui-btn-group-yans").removeClass("layui-btn-group-nans");
    	$("#btns").addClass("layui-btn-group-nans").removeClass("layui-btn-group-yans");
    	$("#diva").show();
    	$("#divb").hide();
    	$("#taba").show();
    	$("#tabb").hide();
    	tableResult.reload();
    });
    
    //绑定事件
    $(document).on('click', '#btns', function(data) {
    	$(this).addClass("layui-btn-group-yans").removeClass("layui-btn-group-nans");
    	$("#btn").addClass("layui-btn-group-nans").removeClass("layui-btn-group-yans");
       	$("#divb").show();
    	$("#diva").hide();
    	$("#tabb").show();
    	$("#taba").hide();
    	 // 渲染表格
    	tableResults.reload();
    });

    // 渲染表格
    var tableResults = table.render({
        title: "已打分列表",
        elem: '#' + bases.tableId,
        url: Feng.ctxPath + '/modular/activity_apply/lists',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: bases.initColumn()
    });

    /**
     * 点击查询按钮
     */
    base.search = function () {
        var queryData = {};
        queryData['userName'] = $("#keyword").val();
        queryData['timeLimit'] = $("#timeLimit").val();
        queryData['division'] = $("#status").find("option:selected").val();
        queryData['userType'] = $("#userType").find("option:selected").val();
        queryData['sex'] = $("#sex").find("option:selected").val();
        table.reload(base.tableId, {
            where: queryData, page: {curr: 1}
        });
    };
    
    /**
     * 点击查询按钮
     */
    bases.searchs = function () {
        var queryData = {};
        queryData['userName'] = $("#keywords").val();
        queryData['timeLimit'] = $("#timeLimits").val();
        queryData['division'] = $("#statuss").find("option:selected").val();
        queryData['userType'] = $("#userTypes").find("option:selected").val();
        queryData['sex'] = $("#sexs").find("option:selected").val();
        table.reload(bases.tableId, {
            where: queryData, page: {curr: 1}
        });
    };


    /**
     * 点击查看通知
     *
     * @param data 点击按钮时候的行数据
     */
    base.onQueryDetails = function (data) {
        func.open({
            type: 2,
            shadeClose: true,
            shade: 0.5,
            area: '300px',
            title: '查看详情',
            maxmin: true, //开启最大化最小化按钮
            content: Feng.ctxPath + "/modular/activity_apply/details/" + data.user_id,
            tableId: base.tableId
        });
    };

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        base.search();
    });
    
    // 搜索按钮点击事件
    $('#btnSearchs').click(function () {
    	bases.searchs();
    });


    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        base.openAddCompany();
    });

    // 导出excel
    $('#btnExp').click(function () {
        base.exportExcel();
    });
    
    // 导出excel
    $('#btnExps').click(function () {
    	bases.exportExcels();
    });

    // 渲染表格
    var tableResult = table.render({
        title: "未打分列表",
        elem: '#' + base.tableId,
        url: Feng.ctxPath + '/modular/activity_apply/list',
        page: true,
        height: "full-98",
        cellMinWidth: 100,
        cols: base.initColumn()
    });
    
    base.exportExcel = function () {
        var checkRows = table.checkStatus(base.tableId);

        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            // table.exportFile([' 表头',' 表头',' 表头',' 表头',' 表头',' 表头'], cons , 'xls',name);
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };
    
    bases.exportExcels = function () {
        var checkRows = table.checkStatus(bases.tableId);

        if (checkRows.data.length === 0) {
            Feng.error("请选择要导出的数据");
        } else {
            // table.exportFile([' 表头',' 表头',' 表头',' 表头',' 表头',' 表头'], cons , 'xls',name);
            table.exportFile(tableResults.config.id, checkRows.data, 'xls');
        }
    };
});

